<template>
  <view>
	  <u-mask :show="show">
		  <view class="job_popup">
		    <view class="job_popup_box">
		      <ShareCompany v-if="type === 'company'" :tplIndex="currentTplIndex" :infoid="infoid" @closePoster="closePoster" @emitImgUrl='getImgUrl'></ShareCompany>
		      <ShareJob v-if="type === 'job'" :tplIndex="currentTplIndex" :infoid="infoid" @closePoster="closePoster" @emitImgUrl='getImgUrl'></ShareJob>
		      <ShareResume v-if="type === 'resume'" :tplIndex="currentTplIndex" :infoid="infoid" @closePoster="closePoster" @emitImgUrl='getImgUrl'></ShareResume>
		      <view class="job_btns">
		        <view class="job_btn_1" @click="changeTpl">换一个</view>
		        <view class="job_btn_2" @click="longPressConserve">保存图片</view>
		      </view>
		    </view>
		  </view>
	  </u-mask>
    
	<u-toast ref="uToast" />
  </view>
</template>

<script>
import ShareCompany from './ShareCompany.vue'
import ShareJob from './ShareJob.vue'
import ShareResume from './ShareResume.vue'
export default {
  name: 'SharePoster',
  props: ['type', 'infoid'],
  components: {
    ShareCompany,
    ShareJob,
    ShareResume
  },
  data () {
    return {
      currentTplIndex: 1,
	  imgUrl:'',
	  show:true
    }
  },
  methods: {
    changeTpl () {
	  this.currentTplIndex++
      if (this.currentTplIndex >= 23) {
        this.currentTplIndex = 1
      }
    },
    // 关闭海报
    closePoster () {
      this.$emit('closePoster')
    },
    longTap () {
	  this.$refs.uToast.show({
		title: '请长按海报图片保存到相册',
		icon:false
	  })
    },
	longPressConserve(){
		var _this = this
		uni.downloadFile({ //通过下载文件api 获取临时路径
			url:this.imgUrl,
			success:(res)=>{
				if(res.statusCode == 200){
					uni.saveImageToPhotosAlbum({ // 保存到系统相册中 (网络地址不支持)
						filePath:res.tempFilePath,//传入临时地址
						success() {
							uni.vibrateShort({
								success(){
									_this.$refs.uToast.show({
										title: '保存成功',
										type:'success',
										icon:false
									 })
								}
							})
						},
						fail() {
							_this.$refs.uToast.show({
								title: '保存失败',
								type:'error',
								icon:false
							 })
						}
					})
				}
			}
		})
	},
	getImgUrl(url){
		this.imgUrl = url
	}
  }
}
</script>

<style lang="scss" scoped>
.job_popup_box{
  position: fixed;
  z-index:4;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
}
  .job_popup_box .job_btns {
    display: flex;
    justify-content: space-between;
    margin-top:39rpx;
  }

  .job_popup_box .job_btns .job_btn_1,
  .job_popup_box .job_btns .job_btn_2 {
    width: 250rpx;
    height: 68rpx;
    text-align: center;
    line-height: 68rpx;
    color: #fff;
    font-size:28rpx;
    border-radius: 10rpx;
  }

  .job_popup_box .job_btns .job_btn_1 {
    background-color: #1787fb;
  }

  .job_popup_box .job_btns .job_btn_2 {
    background-color: #00d77e;
  }
</style>
